package com.ywd.materials.admin.controller;

import com.ywd.materials.admin.common.Common;
import com.ywd.materials.admin.dto.AdminMenuDto;
import com.ywd.materials.admin.dto.query.AdminMenuQuery;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.exception.RPage;
import com.ywd.materials.admin.service.impl.AdminMenuServiceImpl;
import com.ywd.materials.admin.vo.AdminMenuTreeVo;
import com.ywd.materials.admin.vo.AdminMenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lk
 * @date 2024/4/17 13:53
 */
@AllArgsConstructor
@RestController
@RequestMapping("/adminMenu")
@Tag(name = "菜单管理")
public class AdminMenuController {

    private final AdminMenuServiceImpl adminMenuServiceImpl;

    @GetMapping("/getMenuTree")
    @Operation(summary = "菜单列表(树形)")
    public R<List<AdminMenuTreeVo>> getMenuTree() {
        return R.ok(adminMenuServiceImpl.getMenuTree());
    }

    @PostMapping("/getMenuPage")
    @Operation(summary = "菜单列表(分页)")
    public R<RPage<List<AdminMenuVo>>> getMenuPage(@RequestBody AdminMenuQuery query) {
        return R.ok(adminMenuServiceImpl.getMenuPage(query));
    }
    
    @PostMapping("/addMenu")
    @Operation(summary = "新增菜单")
    public R<Boolean> addMenu(@RequestBody AdminMenuDto dto) {
        return R.ok(adminMenuServiceImpl.addMenu(dto));
    }
    
    @PutMapping("/updateMenu")
    @Operation(summary = "修改菜单")
    public R<Boolean> updateMenu(@RequestBody AdminMenuDto dto) {
        return R.ok(adminMenuServiceImpl.updateMenu(dto));
    }

    @DeleteMapping("/deleteMenu")
    @Operation(summary = "删除菜单")
    public R<Boolean> deleteMenu(@Schema(description = "菜单ID") @RequestParam Long id) {
        return R.ok(adminMenuServiceImpl.deleteMenu(id));
    }
    
    @GetMapping("/getMenuPartList")
    @Operation(summary = "菜单列表(筛选项)")
    public R<List<Common>> getMenuPartList(@Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(adminMenuServiceImpl.getMenuPartList(name));
    }

}
